package com.test.daily.leetcode.y2022.m05.day0529.v01;

import java.util.HashSet;
import java.util.Stack;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/5/29 下午 02:16
 * @version: 1.0
 */
public class Code02_DFS {
    public static void dfs(Node start){
        HashSet<Node> set = new HashSet<>();
        Stack<Node> stack = new Stack<>();
        set.add(start);
        stack.add(start);
        System.out.println(start.value);
        while(!stack.isEmpty()){
            Node cur = stack.pop();
            for(Node next: cur.nexts){
                if(!set.contains(next)){
                    System.out.println(next.value);
                    stack.push(cur);
                    stack.push(next);
                    break;
                }
            }
        }
    }
}
